package com.jt.controller;

import com.jt.mapper.ItemCatMapper;
import com.jt.pojo.ItemCat;
import com.jt.service.ItemCatService;
import com.jt.service.ItemService;
import com.jt.vo.PageResult;
import com.jt.vo.SysResult;
import com.sun.org.apache.bcel.internal.generic.NEW;
import com.sun.org.apache.bcel.internal.generic.RETURN;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.omg.PortableInterceptor.SYSTEM_EXCEPTION;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.lang.annotation.Retention;
import java.util.List;
@Slf4j
@RestController
@CrossOrigin
@RequestMapping("/itemCat")
public class ItemCatController {

        @Autowired
        private ItemCatService itemCatService;


        @GetMapping("/hello")
        public  List<ItemCat>  getItemCats(){
                List<ItemCat> allFloorList = itemCatService.getAllFloorList();
                return allFloorList;
        };



        //获取用户列表的信息
        @GetMapping("/findItemCatList")
        public  SysResult   findItemCatList(){
                //            PageResult itemPage = itemService.getItemPage(pageResult);
            List<ItemCat> itemCatList = itemCatService.getItemCatList();
            return SysResult.success(itemCatList);
        }

        @GetMapping("findByLevel/{level}")
        public  SysResult findByLevel(@PathVariable Integer level){
                List<ItemCat> byItemCatList = itemCatService.getByItemCatList(new ItemCat().setLevel(level));
                return  SysResult.success(byItemCatList);

        }

        //根据级别获取商品的信息
        @GetMapping("/findItemCatList/{type}")
        public  SysResult findItemCatList(@PathVariable  Integer type){
                List<ItemCat> bytype = itemCatService.findBytype(type);
                return SysResult.success(bytype);
        }


        //修改商品的状态
        @PutMapping("/status/{id}/{status}")
        public  SysResult  updatestatus(ItemCat itemCat){
                boolean b = itemCatService.updateItemCatByid(itemCat);
                if (b)
                        return   SysResult.success();
                return   SysResult.fail();
        }

        //添加商品的信息
        @PostMapping("saveItemCat")
        public  SysResult  saveItemCar(@RequestBody  ItemCat  itemCat){
                System.out.println(itemCat);
                 itemCatService.save(itemCat);
                 return   SysResult.success();
        }


        //修改商品的分类的信息
        @PutMapping("updateItemCat")
        public  SysResult  updateItemCat(@RequestBody  ItemCat itemCat){
                itemCatService.updateItemCatByid(itemCat);
                return  SysResult.success();
        }

        //删除商品的分类的信息
        @DeleteMapping("deleteItemCat")
        public SysResult  updateIntemCat(Integer  id,Integer  level){
                itemCatService.deleteItemCat(id,level);
                return   SysResult.success();
        }


}
